import actions from '../action/user';
import CONSTANT from '../constant/user';

const userObj = {};
const userDetail = {};
const publicList = [];

export default {
  actions,
  state: {
    userObj,
    userDetail,
    publicList,
  },
  mutations: {
    // 设置编辑的用户信息
    [CONSTANT.SET_EDIT_INFO](state, data) {
      state.userObj = Object.assign({}, ...state, { editUser: data });
    },
    // 获取用户列表
    [CONSTANT.GET_USER_SUCCESS](state, data) {
      state.userObj = Object.assign({}, ...state, { userList: data });
    },
    // 获取用户详情
    [CONSTANT.GET_USER_DETAIL_SUCCESS](state, data) {
      state.userDetail = data;
    },
    // 获取用户详情失败
    [CONSTANT.GET_USER_DETAIL_ERROR](state) {
      state.userDetail = {};
    },
    // 添加用户成功
    [CONSTANT.ADD_USER_SUCCESS](state, data) {
      state.userObj = Object.assign({}, ...state, data);
    },
    // 修改用户信息
    [CONSTANT.EDIT_USER_SUCCESS](state, data) {
      state.userObj = Object.assign({}, ...state, data);
    },
    // 重置密码
    [CONSTANT.RESET_PASSWORD_SUCCESS](state) {
      return state;
    },
    // 改变用户的状态
    [CONSTANT.CHANGE_USER_STATUS_SUCCESS](state) {
      return state;
    },
    // 获取到公众号信息
    [CONSTANT.GET_PUBLIC_ACCOUNTS_SUCCESS](state, data) {
      state.publicList = data;
    },
  },
  getters: {
    [CONSTANT.USER_INFO](state) {
      return state.userObj;
    },
    [CONSTANT.USER_LIST](state) {
      return state.userObj;
    },
    [CONSTANT.PUBLIC_ACCOUNTS](state) {
      return state.publicList;
    },
  },
};
